###############################################################################
# CA cleaning
#
# 11 August 2022
# sbaltz
###############################################################################

import pandas as pd

RAW_FILE_NAME = "../transcribed/los-angeles.csv"
SAVE_FILE_NAME = "../ready/la_cleaned.csv"
COUNTY_NAME = "LOS ANGELES"

ct = pd.read_csv(RAW_FILE_NAME)

cleaned = pd.DataFrame()

office = "ALL"
for i in range(len(ct)):
    if "Vote by Mail" in str(ct["mode"][i]):
        mode = "MAIL-IN"
    elif "Ballot Marking Device" in str(ct["mode"][i]):
        mode = "IN-PERSON"
    if str(ct["mode"][i]) != "nan" and str(ct["ballots"][i]) != "nan":
        try:
            office = "ALL"
            state = "CALIFORNIA"
            county = COUNTY_NAME
            ballots = int(ct["ballots"][i])
            issues = int(ct["issues"][i])
            subset = int(ct["mode"][i])
            method = "MANUAL"
            cleaned = pd.concat([cleaned,
                            pd.DataFrame([[state,county,office,\
                            ballots,issues,subset,mode,method]])],\
                            ignore_index = True)
        except Exception as inst:
            print(inst)

cleaned.columns = ["state","county","office","ballots","issues","subset",\
                   "mode","method"]

cleaned.to_csv(SAVE_FILE_NAME, index=False)
